package fight.view.armytype 
{
	import fight.FightC;
	import flash.display.Bitmap;
	import org.airmvc.Dispatcher;
	import utils.T;
	import vo.GeneralVO;

	/**
	 * 主将
	 * @author WLDragon 2014-05-06
	 */
	public class Leader extends Sowar 
	{
		
		public function Leader(isAttack:Boolean,hp:int,resName:String,dir:int, attackEffect:Bitmap, callBack:Function) 
		{
			super(isAttack,hp,resName,dir,attackEffect,callBack);
		}
		
		public function setDefenseValue(g:GeneralVO):void
		{
			var x:XML = T.db.getXml(Cnt.XML_EQUIP).equip.(@id == g.armorID)[0];
			defenseValue = int(x.@effect);
		}
		
		override protected function bruise(attacker:BaseArmy):void 
		{
			var baseHurt:int = (getFactorB(attacker.hp) * factorA * 0.01) * 0.5 - defenseValue;
			if (baseHurt < 0)
				baseHurt = 0;
				
			hp -= baseHurt;
			
			if (hp <= 0)
			{
				var tx:int = this.x / 32;
				var ty:int = this.y / 32;
				mapData[ty][tx] = null;
				state = 5;
				
				baseHurt = baseHurt + hp;
			}
			
			Dispatcher.send(FightC.UPDATE_INFO_PANEL, this, isAttack, "strength", baseHurt);
			
			if (hp <= 0)
			{
				Dispatcher.send(FightC.LEADER_ESCAPE_OR_DIE,this);
				parent.removeChild(this);
			}
		}
		
		private var defenseValue:int;
	}

}